package com.lqe.study.Servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;

@WebServlet("/ServletDemo02")
public class ServletDemo02 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = this.getServletContext();
        String user = "lisi";
        servletContext.setAttribute("user",user);

        String contextPath = req.getContextPath();
        System.out.println(contextPath);

        String method = req.getMethod();
        System.out.println(method);

        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURL);

        String servletPath = req.getServletPath();
        System.out.println(servletPath);

        String queryString = req.getQueryString();
        System.out.println(queryString);

        String username = req.getParameter("username");
        System.out.println(username);

        Enumeration<String> parameterNames = req.getParameterNames();

        while(parameterNames.hasMoreElements()){
            System.out.println(parameterNames.nextElement());
        }
        String[] parameterValues = req.getParameterValues("hobby");
        for (int i = 0; i < parameterValues.length; i++) {
            System.out.println(parameterValues[i]);
        }
        System.out.println("我是doGet方法");

    }
}


